﻿// -----------------------------------------------------------------------
// <copyright file="NPWebApp.cs" company="Accenture">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace NPSoft.Ferrero.Framework.Web
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using NPSoft.Ferrero.Framework.Crosscutting;
    using NPSoft.Ferrero.Framework.BLL;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class NPWebApp
    {
        private static List<IAppConfig> _apps = new List<IAppConfig>();
        private static List<IWebConfig> _webs = new List<IWebConfig>();
        private static INPContainer _container;

        /// <summary>
        /// 设置当前的依赖注入容器。
        /// </summary>
        /// <param name="container">依赖注入容器</param>
        public static void SetContainer(INPContainer container)
        {
            _container = container;
        }

        /// <summary>
        /// 获取当前的依赖注入容器。
        /// </summary>
        public static INPContainer Container
        {
            get { return _container; }
        }

        /// <summary>
        /// 配置系统。
        /// </summary>
        public static void ConfigureSystem()
        {
            foreach (IWebConfig webConfig in _webs)
            {
                webConfig.ConfigureSystem();
            }
            foreach (IAppConfig appConfig in _apps)
            {
                appConfig.ConfigureSystem();
            }
        }

        /// <summary>
        /// 注册系统应用层配置。
        /// </summary>
        /// <param name="config"></param>
        public static void RegisterApp(IAppConfig config)
        {
            var cnt = _apps.Count();
            if (cnt > 0)
            {
                throw new ArgumentException("Registed Fail!");
            }
            _apps.Add(config);
        }

        /// <summary>
        /// 注册系统展示层配置。
        /// </summary>
        /// <param name="config"></param>
        public static void RegisterWeb(IWebConfig config)
        {
            var cnt = _webs.Count();
            if (cnt > 0)
            {
                throw new ArgumentException("Registed Fail!");
            }
            _webs.Add(config);
        }
    }
}
